package com.quanyue.mechanics.complex.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.mechanics.complex.service.JournalismService;
import com.quanyue.mechanics.domain.entity.Journalism;
import com.vhuomai.mybatis.mapper.page.Page;
import com.vhuomai.mybatis.mapper.page.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@Api(tags = "新闻资讯")
@RestController
@RequestMapping("/api")
public class JournalismController {
    @Autowired
    private JournalismService journalismService;

    @ApiOperation(value = "添加资讯")
    @PostMapping(value = "/journalism", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Journalism> addJournalism(@RequestBody Journalism journalism) {
        return ServiceResult.success(journalismService.addJournalism(journalism));
    }

    @ApiOperation(value = "修改资讯")
    @PutMapping(value = "/journalism", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Boolean> updateJournalism(@RequestBody Journalism journalism) {
        journalismService.updateJournalism(journalism);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "删除资讯")
    @DeleteMapping(value = "/journalism", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Boolean> deleteJournalism(@RequestParam("id") Integer id) {
        journalismService.deleteJournalism(id);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "资讯列表")
    @PostMapping(value = "/journalism/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Page <Journalism>> findJournalism(@RequestBody PageRequest request) {
        return ServiceResult.success(journalismService.findJournalism(request));
    }
}
